#include "../head/listHelper.cpp"
#include <cassert>


// 237 delete Node  非尾节点
class DeleteNode{
public:
    void deleteNode(ListNode* node) {
		if(node == null) return;
		if(node->next == NULL){
			delete node;
			node == NULL；
			return;
		}
     	assert(node != NULL && node->next != NULL);
		// 当前节点值赋值给下一个节点  改变该节点值
		node->val = node->next->val;
		ListNode* delNode = node->next;
		node->next = delNode->next;

		delete delNode;

		return;		
    }

};
int main(){
	int arr[] = {1, 2, 3, 4};
    int n = sizeof(arr)/sizeof(int);
	
	ListNode* head = createLinkedList(arr, n);
    printLinkedList(head);

	// 找到值为2的节点, 并调用我们的算法删除
    ListNode* node2 = findNode(head, 2);
    DeleteNode().deleteNode(node2);
    printLinkedList(head);

    deleteLinkedList(head);

    return 0;
}
